package internal

import (
	"app/internal/api/chat"
	"app/internal/api/demo"
	"app/internal/api/goods"
	"app/internal/bootstrap"
	"github.com/gin-gonic/gin"
	"time"
)

func init() {
	//注册路由
	bootstrap.RegisterHttpRouter(defaultRouter(), bizRouter())
}

func bizRouter() func(r *gin.Engine) {
	//业务路由
	return func(r *gin.Engine) {
		//验证token
		//r.Use(middleware.JwtTokenCheck())
		//TODO 按照模块去注册路由组，在模块中实现具体路由的控制
		demo.Router(r.Group("/demo"))   //demo模块
		goods.Router(r.Group("/goods")) // 商品模块
		chat.Router(r.Group("/chat"))   //聊天模块
	}
}

func defaultRouter() func(r *gin.Engine) {
	//默认路由
	return func(r *gin.Engine) {
		// default
		r.GET("/", func(c *gin.Context) {
			c.String(200, time.Now().Format("2006-01-02 15:04:05"))
		})
		// ping
		r.GET("/ping", func(c *gin.Context) {
			c.String(200, "pong!")
		})
		//404
		r.NoRoute(func(c *gin.Context) {
			c.AbortWithStatus(404)
		})
	}
}
